﻿<?php
$email=trim(@$_POST["email"]);
$key=trim(@$_POST["key"]);
$partner=trim(@$_POST["partner"]);
if ($email!="" && $key!="" && $partner!=""){
	echo savepayinfo($email,$key,$partner);
} 


function getconn(){
	
	$connstr = "DRIVER=Microsoft Access Driver (*.mdb); DBQ=D:\WWW\zfutest\mydb.mdb"; 
	$conn=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC);
	return $conn;
} 

//客户的付款资料
function savepayinfo($email,$key,$partner){
	$conn=getconn();
	$sql="update account set email='".$email."',key='".$key."',partner='".$partner."' where username='guest'";
	$result=odbc_exec($conn, $sql);
	if (odbc_num_rows($result)==1){
	odbc_close($conn);
	return "ok";
	}
}

function  updateloginnum(){
	$conn=getconn();
	$sql="select loginnum from account where username='guest'";
	$result=odbc_exec($conn, $sql);
	$loginnum=odbc_result($result, 1);
	$sql2="update account set loginnum='".($loginnum+1)."' where username='guest'";
	odbc_exec($conn, $sql2);
	odbc_close($conn);
}

function getbalance(){
	$conn=getconn();
	$sql="select balance from account where username='guest'";
	$result=odbc_exec($conn, $sql);
	//odbc_fetch_row($result);
	$balance=odbc_result($result, "balance");
	odbc_close($conn);
	return  $balance;
}

function savelist($title,$payAmount){
	$conn=getconn();
	$sql=
"insert into orderlist([time],trsno,channel,states,price) 
	values('".date("Y.m.d H:m:s")."','".substr($title, 3)."','".iconv("utf-8", "gb2312", "支付宝在线充值")."','".iconv("utf-8", "gb2312", "未入账")."','".$payAmount."')";
	odbc_exec($conn, $sql);
	
	odbc_close($conn);
}

function  getpayinfo(){
	$conn=getconn();
	$sql="select email,key,partner from account where username='guest'";
	$result=odbc_exec($conn, $sql);
	$payinfo['seller_email']=odbc_result($result, 1);
	$payinfo['key']=odbc_result($result, 2);
	$payinfo['partner']=odbc_result($result, 3);
	odbc_close($conn);
	return  $payinfo;
}

function updatestates($out_trade_no,$trade_amount){
		$conn=getconn();
		$sql="update orderlist set states='".iconv("utf-8", "gb2312","充值成功")."' where trsno='".$out_trade_no."'";
		$result=odbc_exec($conn, $sql);
		if (odbc_num_rows($result)==1)
		odbc_close($conn);
		setbalance($trade_amount);
}

function setbalance($trade_amount){
		$conn=getconn();
		$sql="update account set balance='".($trade_amount+getbalance())."' where username='guest'";
		$result=odbc_exec($conn, $sql);
		if (odbc_num_rows($result)==1)
		odbc_close($conn);
}

?>